package com.lagou.springBootRocketmq.controller;

import com.lagou.springBootRocketmq.entity.Person;
import com.lagou.springBootRocketmq.util.FastJsonUtils;
import com.lagou.springBootRocketmq.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/redis")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("/findString")
    public String findString(String key) {
        Object o = redisTemplate.opsForValue().get(key);
        return o.toString();
    }

    @RequestMapping("/findObject")
    public String findObject(String key) {
        Object o = redisUtil.get(key);
        Person person = FastJsonUtils.stringToBean(o.toString(), Person.class);
        return person.toString();
    }

}
